﻿using System;
using System.Net;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;
using System.Windows;
using System.Collections.Generic;

namespace LastStand.gameContent.Friendlies
{
    public class Build
    {
		//isVisible
		public bool isVis;

        //create the ability to manipulate the view
        ViewControl view;

        //rifle tower build option
        Button RifleTowerButton;
        Button WallButton;
        Button BarracksButton;

        //init the canvas the build options will sit on
        public Canvas BuildMenu;

        //build textures
        Texture2D SetRifle;
        Texture2D SetWall;
        Texture2D Map;
        Texture2D RifleTower;

        //create a temp spriteList for adding a build sprite
        List<Sprite> spriteList;

        //create a temp view control for spawning objects

        public Build(Grid grid, List<Sprite> list, ViewControl view, ContentManager content)
        {
            //make the spritelist available throughout the entire scope for button interaction
            this.spriteList = list;
            this.view = new ViewControl(new Vector2(0, 0), content.Load<Texture2D>("Map"), grid);


            //create the rifle tower button
            RifleTowerButton = new Button();
            RifleTowerButton.Height = 50;
            RifleTowerButton.Width = 200;
            RifleTowerButton.Content = "Build Rifle Tower";
            RifleTowerButton.FontSize = 14;
            RifleTowerButton.Margin = new Thickness(0, 0, 0, 0);
            RifleTowerButton.Click += new RoutedEventHandler(RifleTowerButton_Click);

            //create wall structure button
            WallButton = new Button();
            WallButton.Height = 50;
            WallButton.Width = 200;
            WallButton.Content = "Build a Wall";
            WallButton.FontSize = 14;
            WallButton.Margin = new Thickness(200, 0, 0, 0);
            WallButton.Click += new RoutedEventHandler(WallButton_Click);

            //create thre canvas the buttons will sit on
            BuildMenu = new Canvas();
            BuildMenu.Name = "BuildMenu";
            BuildMenu.Width = 600;
            BuildMenu.Height = 50;
            BuildMenu.SetValue(Canvas.HorizontalAlignmentProperty, HorizontalAlignment.Left);
            BuildMenu.SetValue(Canvas.VerticalAlignmentProperty, VerticalAlignment.Top);
            BuildMenu.SetValue(Canvas.MarginProperty, new Thickness(100,0,0,0));
            BuildMenu.SetValue(Canvas.BackgroundProperty, new SolidColorBrush(Colors.Black));

            //embed the UI elements
            grid.Children.Add(BuildMenu);
            BuildMenu.Children.Add(RifleTowerButton);
            BuildMenu.Children.Add(WallButton);


        }

        public void Update(GameTimerEventArgs timer, List<Sprite> spriteList)
        {
            view.Update(timer, spriteList);
        }

        public void Draw(SpriteBatch sb)
        {
            view.Draw(sb);
        }

        public void Load(ContentManager content)
        {
            SetRifle = content.Load<Texture2D>("buildTower");
            SetWall = content.Load<Texture2D>("Test Day");
            Map = content.Load<Texture2D>("Map");
            RifleTower = content.Load<Texture2D>("RifleTower");
        }

        void RifleTowerButton_Click(object sender, RoutedEventArgs e)
        {
            if (spriteList[spriteList.Count - 1].isConstructed == false)
                spriteList.RemoveAt(spriteList.Count - 1);
            spriteList.Add(new RifleTower(new Vector2(400, 240), SetRifle));
        }

        void WallButton_Click(object sender, RoutedEventArgs e)
        {
            if (spriteList[spriteList.Count - 1].isConstructed == false)
                spriteList.RemoveAt(spriteList.Count - 1);
			spriteList.Add(new Wall(new Vector2(400, 240), 20, SetWall));
        }
    }
}
